package com.okami.domain.onlineshop.converter;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;

import javax.persistence.AttributeConverter;
import java.util.Map;

/**
 * @author: TanJingyu
 * @create: 2020-12-22 17:12
 **/
public class MapStringConverter implements AttributeConverter<Map<String,String>,String> {
    @Override
    public String convertToDatabaseColumn(Map attribute) {
        return JSON.toJSONString(attribute);
    }

    @Override
    public Map<String,String> convertToEntityAttribute(String dbData) {
        return JSON.parseObject(dbData, new TypeReference<Map<String, String>>() {});
    }
}
